
package com.xxl.job.core.commons.annotation.impl;



import com.xxl.job.core.commons.annotation.NameSpaceCheck;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @Description : 名字空格校验实现
 * @Author : tanxingsong
 * @Date : 13:35 2019/2/21
 * @Email : tanxingsong@cetcbigdata.com
 */
public class NameSpaceCheckImpl implements ConstraintValidator<NameSpaceCheck, String> {
    @Override
    public void initialize(NameSpaceCheck constraintAnnotation) {
    }

    @Override
    public boolean isValid(String name, ConstraintValidatorContext context) {
        // 检测首尾不为空格
        if (null != name && !"".equals(name)) {
            if (name.substring(0, 1).equals(" ") || name.substring(name.length() - 1).equals(" ")) {
                return false;
            }
        }
        return true;
    }
}
